﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Data;

namespace CommunitySystemModel
{
    [Serializable]
    [DataContract]
    public class RoleMenu
    {
        private int? _ID;
        [DataMember]
        public int? ID
        {
            get { return _ID; }
            set { _ID = value; }
        }

        private int? _RoleID;
        [DataMember]
        public int? RoleID
        {
            get { return _RoleID; }
            set { _RoleID = value; }
        }


        private int _MenuID;
        [DataMember]
        public int MenuID
        {
            get { return _MenuID; }
            set { _MenuID = value; }
        }

        [DataMember]
        private MenuItem Menu = new MenuItem();

        public MenuItem _MenuItem
        {
            get { return Menu; }
            set { Menu = value; }
        }
        


        /// <summary>
        /// m.ID as MenuID, m.Title, m.[Target], m.[Index], m.PID, m.icon, rm.ID as RoleMenuID, rm.RoleID 
        /// </summary>
        /// <param name="dr"></param>
        public static RoleMenu FillEntity(DataRow dr)
        {
            RoleMenu right = new RoleMenu();
            right.ID = dr["RoleMenuID"] as int?;
            right.RoleID = dr["RoleID"] as int?;
            right.MenuID = (int)dr["MenuID"];
            right._MenuItem.ID = right.MenuID;
            right._MenuItem.Title = dr["Title"] as string;
            right._MenuItem.Target = dr["Target"] as string;
            right._MenuItem.PID = (int)dr["PID"];
            right._MenuItem.icon = dr["icon"] as byte[];
            return right;
        }
    }
}
